package cn.zyq.ykb.controller.mgt.product;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.product.ProductType;
import cn.zyq.ykb.service.product.ProductTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品类型Controller
 *
 * @author SystemAuth
 * @date 2023-11-02
 */

@RestController(value = "MgtProductTypeController")
@RequestMapping("/mgt/productType")
@Api(tags = "商品类型接口")
public class ProductTypeController extends BaseController {

    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 查询商品类型列表
     */
    @ApiOperation(value = "列表", response = ProductType.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.productTypeService.selectProductTypeList(pageParam);
    }

     /**
      * 导出商品类型列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "商品类型" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, @RequestBody PageParam pageParam) {
         List<ProductType> list = productTypeService.selectProductTypeAllList(pageParam);
         ExcelUtil<ProductType> util = new ExcelUtil<ProductType>(ProductType. class);
         util.exportExcel(response, list, "商品类型数据");
     }

    /**
     * 获取商品类型详细信息
     */
    @ApiOperation(value = "详情", response = ProductType.class)
    @GetMapping(value = "/{productTypeID}")
    public Object getInfo(@PathVariable("productTypeID") Integer productTypeID) {
        return this.productTypeService.selectProductTypeByProductTypeID(productTypeID);
    }
    /**
     * 获取商品类型详细信息
     */
    @ApiOperation(value = "详情", response = ProductType.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.productTypeService.selectProductTypeByServiceID(serviceID);
    }

    /**
     * 新增商品类型
     */
    @ApiOperation(value = "新增")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody ProductType productType) {
        return this.productTypeService.insertProductType(productType);
    }

    /**
     * 修改商品类型
     */
    @ApiOperation(value = "编辑")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody ProductType productType) {
        return this.productTypeService.updateProductType(productType);
    }

    /**
     * 删除商品类型
     */
    @ApiOperation(value = "删除")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productTypeIDs}")
    public Object remove(@PathVariable Integer[] productTypeIDs) {
        return this.productTypeService.deleteProductTypeByProductTypeIDs(productTypeIDs);
    }
}
